package com.atguigu.mpdemo101.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author abc
 * @version 1.0
 * @date 2021/3/2 12:49
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private static final Logger LOGGER =  LoggerFactory.getLogger(MyMetaObjectHandler.class);
    //使用mp实现添加，就会执行
    @Override
    public void insertFill(MetaObject metaObject) {  //元数据对象
        LOGGER.info("start insert fill ....");
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
        this.setFieldValByName("version",1,metaObject);
        this.setFieldValByName("deleted", 0, metaObject);


    }
    //使用mp实现修改，就会执行
    @Override
    public void updateFill(MetaObject metaObject) {
        LOGGER.info("start update fill ....");
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

}
